import {ADD_TO_CART, ADD_COUNT} from "@/store/mutations-types";

export default {
  addCart(context, payload) {
    return new Promise((res, rej) => {
      let oldPayload = context.state.cartList.find(item => item.iid === payload.iid)

      if (oldPayload) {
        context.commit(ADD_COUNT, oldPayload)
        res(' 当前商品+1')
      } else {
        payload.count = 1
        context.commit(ADD_TO_CART, payload)
        res('当前商品添加成功')
      }
    })
  }
}
